package com.ruoyi.erp.controller;

import java.util.List;

import com.ruoyi.erp.domain.Project;
import com.ruoyi.erp.service.IProjectService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erp.domain.ProjectBonusUser;
import com.ruoyi.erp.service.IProjectBonusUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目提成用户Controller
 * 
 * @author sauger
 * @date 2022-04-21
 */
@Controller
@RequestMapping("/erp/projectBonusUser")
public class ProjectBonusUserController extends BaseController
{
    private String prefix = "erp/projectBonus/user";

    @Autowired
    private IProjectBonusUserService projectBonusUserService;
    @Autowired
    private IProjectService projectService;

    @RequiresPermissions("erp:projectBonus:user:view")
    @GetMapping()
    public String projectBonusUser()
    {
        return prefix + "/allProjectBonusUser";
    }

    @RequiresPermissions("erp:projectBonus:user:view")
    @GetMapping("/project/{id}")
    public String projectBonusUserById(@PathVariable("id") Integer id, ModelMap mmap){
        Project project = projectService.selectProjectById(id);
        mmap.put("project", project);
        return prefix + "/project/projectBonusUser";
    }

    @GetMapping("/project/{id}/add")
    public String addByProject(@PathVariable("id") Integer id, ModelMap mmap)
    {
        Project project = projectService.selectProjectById(id);
        mmap.put("project", project);
        return prefix + "/project/add";
    }

    /**
     * 查询项目提成用户列表
     */
    @RequiresPermissions("erp:projectBonus:user:list")
    @PostMapping("/project/{id}/list")
    @ResponseBody
    public TableDataInfo listByProject(ProjectBonusUser projectBonusUser)
    {
        startPage();
        List<ProjectBonusUser> list = projectBonusUserService.selectProjectBonusUserList(projectBonusUser);
        return getDataTable(list);
    }

    /**
     * 修改项目提成用户
     */
    @RequiresPermissions("erp:projectBonus:user:edit")
    @GetMapping("/project/{projectId}/edit/{id}")
    public String editByProject(@PathVariable("projectId") Integer projectId, @PathVariable("id") Integer id, ModelMap mmap)
    {
        ProjectBonusUser projectBonusUser = projectBonusUserService.selectProjectBonusUserById(id);
        mmap.put("projectBonusUser", projectBonusUser);
        return prefix + "/project/edit";
    }


    /**
     * 查询项目提成用户列表
     */
    @RequiresPermissions("erp:projectBonus:user:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProjectBonusUser projectBonusUser)
    {
        startPage();
        List<ProjectBonusUser> list = projectBonusUserService.selectProjectBonusUserList(projectBonusUser);
        return getDataTable(list);
    }

    /**
     * 导出项目提成用户列表
     */
    @RequiresPermissions("erp:projectBonus:user:export")
    @Log(title = "项目提成用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProjectBonusUser projectBonusUser)
    {
        List<ProjectBonusUser> list = projectBonusUserService.selectProjectBonusUserList(projectBonusUser);
        ExcelUtil<ProjectBonusUser> util = new ExcelUtil<ProjectBonusUser>(ProjectBonusUser.class);
        return util.exportExcel(list, "项目提成用户数据");
    }

    /**
     * 新增项目提成用户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存项目提成用户
     */
    @RequiresPermissions("erp:projectBonus:user:add")
    @Log(title = "项目提成用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProjectBonusUser projectBonusUser)
    {
        return toAjax(projectBonusUserService.insertProjectBonusUser(projectBonusUser));
    }

    /**
     * 修改项目提成用户
     */
    @RequiresPermissions("erp:projectBonus:user:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        ProjectBonusUser projectBonusUser = projectBonusUserService.selectProjectBonusUserById(id);
        mmap.put("projectBonusUser", projectBonusUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目提成用户
     */
    @RequiresPermissions("erp:projectBonus:user:edit")
    @Log(title = "项目提成用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProjectBonusUser projectBonusUser)
    {
        return toAjax(projectBonusUserService.updateProjectBonusUser(projectBonusUser));
    }

    /**
     * 删除项目提成用户
     */
    @RequiresPermissions("erp:projectBonus:user:remove")
    @Log(title = "项目提成用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(projectBonusUserService.deleteProjectBonusUserByIds(ids));
    }
}
